//Data manipulation
use organisation
encode orgid, gen(orgid1)
encode RegisteredStatus, gen(regstat)
recode regstat 1=0
recode regstat 2=1
label define regstat 0 "Dead" 1 "Live", replace
label values regstat regstat
label variable regstat "Reistration status"
gen incorpdate = date(IncorporationDate,"MDY")
format %tdMonth_DD,_CCYY incorpdate
gen yrcreated=year(incorpdate)
keep if yrcreated==2012
tab LegalForm
gen yrdied=year(DissolvedDate)
gen survivaltime = yrdied-yrcreated
//Setting observations for capitalist firms//
forval i=371/269530 {
	set obs `i'
	
	}

//Generating organisational variable//
gen organisation = 1 if yrcreated == 2012
recode organisation .=0
//Coding capitalist firm and coop data
replace survivaltime = 1 in 371/47129
replace regstat = 0 in 371/47129
replace survivaltime = 2 in 47130/86192
replace regstat = 0 in 47130/86192
replace survivaltime = 3 in 86193/110422
replace regstat = 0 in 6193/110422
replace survivaltime = 4 in 110423/129982
replace regstat = 0 in 110423/129982
replace survivaltime = 5 in 129983/246192
replace regstat = 1 in 129983/246192

recode survivaltime .=0 if organisation == 0
recode regstat .=0 if organisation == 0
recode survivaltime .=5
gen diedonyear = survivaltime+1
label variable diedonyear "Died on year"
recode regstat 0=1 if diedonyear == 6
recode diedonyear 7/8=6
recode regstat 0=1 if diedonyear == 6
save survival_experimental, replace
//Deleting unnecessary variables//
keep organisation diedonyear regstat
//Data analysis//
set scheme s1mono
stset diedonyear, failure(regstat==0)
label define organisation 0 "Capitalist firm" 1 "Cooperative", replace
label values organisation organisation
stcox organisation
estat phtest
est store survival
esttab survival, eform, using survival.rtf, replace
label var organisation "Cooperative"
//Generating tables and graphs//
esttab survival using survival.rtf, ///
obslast se(3) eform nonumber label title(Table 5. Cox porportional hazrds model on firm survival) ///
mtitles("Hazard ratio") replace
stphplot, by(organisation) 
stcoxkm, by(organisation)
sts graph, by(organisation) ci 
sts list, survival by(organisation)
sts graph, cumhaz by(organisation) ci
sts list, cumhaz by(organisation)
sts graph, hazard noboundary by(organisation) ci